﻿using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Controls;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Avalonia;
using CommunityToolkit.Mvvm.Messaging;
using 畜牧业审核程序国产.Models;

namespace 畜牧业审核程序国产.ViewModels
{

    internal class ChoseRagWindowViewModel : ObservableObject
    {
        private int _selectedOption = 1;//默认选中第一项

        // 1: Option 1, 2: Option 2, 3: Option 3
        public int SelectedOption
        {
            get => _selectedOption;
            set => SetProperty(ref _selectedOption, value);
        }
        public RelayCommand OpenChatWindowCommand { get; private set; }
        public ChoseRagWindowViewModel()
        {
            this.OpenChatWindowCommand = new RelayCommand(OpenDiffrentChatWindow);
        }
        public void OpenDiffrentChatWindow()
        {
            string _apiKey = null;
            string _apiUrl = null;
            string _ragModel = null;
            if (SelectedOption == 1)
            {
                _apiKey = "sk-4487d1c2764d4c388af7a241ed28c7f4";
                _apiUrl = "https://dashscope.aliyuncs.com/api/v1/apps/c08d698e5e9e48d7bf36cc184ac8df10/completion";
                _ragModel = "通义千问业务知识库";
            }
            else if (SelectedOption == 2)
            {
                _apiKey = "sk-4487d1c2764d4c388af7a241ed28c7f4";
                _apiUrl = "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions";
                _ragModel = "RagFlow知识库";
            }
            else if(SelectedOption==3)
            {
                _apiKey = "sk-4487d1c2764d4c388af7a241ed28c7f4";
                _apiUrl = "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions";
                _ragModel = "通义千问普通模型";
            }
            else
            {
                _apiKey = "sk-4487d1c2764d4c388af7a241ed28c7f4";
                _apiUrl = "https://dashscope.aliyuncs.com/api/v1/apps/0190dd7b5b6943b88e5e9b1592c43279/completion";
                _ragModel = "通义千问统计法律知识库";
            }
            ////还是通过WeakReferenceMessenger发消息吧
            //TransmitAPIMsgs transmitAPIMsgs = new TransmitAPIMsgs(_apiKey, _apiUrl, _ragModel);
            //WeakReferenceMessenger.Default.Send(transmitAPIMsgs);
            //Window chatWindow = new ChatWindow();

            //var chatWindowViewModel = new ChatWindowViewModel( _apiKey,_apiUrl,_ragModel);
            // var chatWindow = new ChatWindow() { DataContext = chatWindowViewModel };这样就不是MVVM了
            var chatWindow = new ChatWindow(_apiKey, _apiUrl, _ragModel);//这里后续必须修改,因为违反了mvvm模式
            //WeakReferenceMessenger.Default.Send(chatWindow);暂时不起效果
            chatWindow.Show();
        }
    }
    public class TransmitAPIMsgs
    {
        public string APIKey { get; set; }
        public string APIUrl { get; set; }
        public string RagModel { get; set; }
        public TransmitAPIMsgs(string apiKey, string apiUrl, string ragModel)
        {

            this.APIKey = apiKey;
            this.APIUrl = apiUrl;
            this.RagModel = ragModel;
        }
    }
}
